import { randomNum } from "./../../scripts/utils";
const X_AXIS_MONTHS = {
  1: "一月",
  2: "二月",
  3: "三月",
  4: "四月",
  5: "五月",
  6: "六月",
  7: "七月",
  8: "八月",
  9: "九月",
  10: "十月",
  11: "十一月",
  12: "十二月"
};

const getNewYearXAxis = () => {
  const date = new Date();
  let month = date.getMonth() + 1;
  // let year = date.getFullYear();
  let _xAxis = [];
  for (let isMonth in X_AXIS_MONTHS) {
    if (month != isMonth) {
      _xAxis.push(X_AXIS_MONTHS[isMonth]);
    }
  }
  //${year - 1}年
  _xAxis.unshift(`${X_AXIS_MONTHS[month]}`);

  return _xAxis;
};

// eslint-disable-next-line no-unused-vars
const getSeries = (_xAxis, data = []) => {
  let result = [[], []];
  _xAxis.forEach(() => {
    result[0].push(randomNum(1, 1000));
    result[1].push(randomNum(1, 1000));
  });
  return result;
};

export const getTrendByMapOptions = data => {
  const xAxis = getNewYearXAxis();
  const series = getSeries(xAxis, data);
  return {
    color: ["#C4E14E", "#7CE6FD"],
    legend: {
      data: ["批准户数", "批准宅基地面积"]
    },
    grid: {
      top: "10%",
      left: "3%",
      right: "4%",
      bottom: "15%",
      containLabel: true
    },
    xAxis: {
      axisLine: {
        lineStyle: {
          color: "rgba(255,255,255,0.4)"
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ["rgba(255,255,255,0.1)"],
          width: 1,
          type: "solid"
        }
      },
      type: "category",
      data: xAxis
    },
    yAxis: {
      type: "value",
      axisLine: {
        lineStyle: {
          color: "rgba(255,255,255,0.4)"
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: ["rgba(255,255,255,0.1)"],
          width: 1,
          type: "solid"
        }
      }
    },
    series: [
      {
        type: "line",
        smooth: true,
        // areaStyle: {},
        itemStyle: { normal: { label: { show: true } } },
        data: series[0]
      },
      {
        type: "line",
        smooth: true,
        // areaStyle: {},
        itemStyle: { normal: { label: { show: true } } },
        data: series[1]
      }
    ]
  };
};
